const data = [
  "https://s1.aigei.com/src/img/gif/a7/a7f9338864d04584bed17570f5191bee.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:N2QSjfVmeQK7fCQZP5gOtc9ReG4=",
  "https://s1.aigei.com/src/img/gif/9d/9d3063ce904143d288ae55c284440ebf.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:dnMXhlheYb6e9pHd-MKfwF6shRs=",
  "https://s1.aigei.com/src/img/gif/a0/a01638e6fc7b406db654c6272baea4e8.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:pwsqAJah02auTvoiQWOlklBGaHE=",
  "https://s1.aigei.com/src/img/gif/e5/e5cf363ba53b45b58a85bbc0cebdf9e8.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:rDcXIagsKQHAxidgk-iIxO3FK5w=",
  "https://s1.aigei.com/src/img/gif/27/2704f580581649f395c7c4b81fd2769d.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:mklY-roxcef4pPQq-mg5Y9XSqfE=",
  "https://s1.aigei.com/src/img/gif/f2/f2000d99d706401c8dc443abd3164ca0.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:tGoloOkmiyZQ_WwX5pnM3Wjh91c=",
  "https://s1.aigei.com/src/img/gif/84/84538c271bdb46f5a2066760b1fb6dd5.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:8hzCHWceTJG5HhzWc3-YGFtwNTs=",
  "https://s1.aigei.com/src/img/gif/49/49754d9ec1d243ae94a61255b399da03.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:dMkvS-PGJA5GlXDe0_VWCko7Otc=",
  "https://s1.aigei.com/src/img/gif/a5/a5788be7489e4a8faa5b2c382ea0efe9.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:J-p1BRXRP2u0RoLu0m8Wgl2cXqo=",
  "https://s1.aigei.com/src/img/gif/8a/8add857186f946489679f27af4200286.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:HCNFbD09tnl6sFgFVeFf9ZRV2U8=",
  "https://s1.aigei.com/src/img/gif/5c/5c9142862ce14b3bb9cd76e4d9aef5cb.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:ZFaUiZf5VYwVfHhBwnynLYL3xPI=",
  "https://s1.aigei.com/src/img/gif/82/823c2c3ffe7342c288397c71e771c26d.gif?imageMogr2/auto-orient/thumbnail/!282x282r/gravity/Center/crop/282x282/quality/85/%7CimageView2/2/w/282&e=2051020800&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:m_bjl9Xr-31-sRizKLpd1eEDAoU=",
];

const fs = require('fs');
const { Buffer } = require('buffer');
const startIndex = 161

// 将 Blob 对象保存为文件
function saveAsFile(name, blob) {
  blobToBuffer(blob).then(data => {
    fs.writeFile(`${name}.gif`, data, (err) => {
      if (err) throw err;
      console.log(`The file has been saved! [${name}.gif]`);
    });
  })
}

// 将 Blob 对象转换为 Buffer
const blobToBuffer = async (blob) => {
  const arrayBuffer = await blob.arrayBuffer();
  const buffer = Buffer.from(arrayBuffer);
  return buffer;
};

// 批量下载
function start(data) {
  data.forEach((e, i) => {
    setTimeout(() => {
      fetch(e)
        .then(response => response.blob())
        .then(res => {
          saveAsFile(startIndex + i, res);
        })
        .catch(error => console.error(`第${i}张图片下载失败:`, error));
    }, 500);
  })
}

// 单个下载
function startSingle(url, i) {
  fetch(url)
    .then(response => response.blob())
    .then(res => {
      saveAsFile(startIndex + i, res);
    })
    .catch(error => console.error(`第${i}张图片下载失败:`, error));
}

// 开始批量下载
// start(data)
// 查漏补缺批量下载
// [488].forEach(e => {
//   startSingle(data[e - startIndex], e - startIndex)
// })